import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from BeautifulSoup import BeautifulSoup
from appengine_utilities import sessions
import xmw
from xmw.db import ds
import simplejson
import logging
from xmw.db import user_mgr

class MainPage(xmw.RequestHandler):
    def get(self):
        self.sess = sessions.Session()
        self.cookie_sess = sessions.Session(writer="cookie")    
        session_user =None
        if self.sess.has_key("user"):
            session_user=self.sess["user"]
        (key_word,e) = self.get_key_from_GET('search_key_word')
        if key_word is not None:
            key_word  =key_word.strip()
            #title   =self.xmw_decoding(title)
            
        self.sess['login_action']=ds.Login_Action(action="/search",params="q="+key_word)
        self.sess['login_action'].put()
        self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
        data={"ok":True}
        data_js= simplejson.dumps(data)
        self.response.out.write(data_js)
        return
    
                
        
def main():
    application = webapp.WSGIApplication(
                                       [('/j/subscribe/set_login_action', MainPage)],
                                       debug=True)
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()